import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsOptional, IsBoolean, IsNumber, Min, Max } from 'class-validator';
import { Transform } from 'class-transformer';

export class RoleQueryDto {
  @ApiProperty({
    description: '角色名称',
    required: false,
    example: '管理员'
  })
  @IsOptional()
  @IsString()
  name?: string;

  @ApiProperty({
    description: '角色编码',
    required: false,
    example: 'ADMIN'
  })
  @IsOptional()
  @IsString()
  code?: string;

  @ApiProperty({
    description: '角色状态',
    required: false,
    example: true
  })
  @IsOptional()
  @Transform(({ value }) => value === 'true' ? true : value === 'false' ? false : value)
  @IsBoolean()
  status?: boolean;

  @ApiProperty({
    description: '当前页码',
    required: false,
    default: 1,
    minimum: 1
  })
  @IsOptional()
  @Transform(({ value }) => parseInt(value))
  @IsNumber()
  @Min(1, { message: '页码不能小于1' })
  pageNum: number = 1;

  @ApiProperty({
    description: '每页显示数量',
    required: false,
    default: 10,
    minimum: 1,
    maximum: 100
  })
  @IsOptional()
  @Transform(({ value }) => parseInt(value))
  @IsNumber()
  @Min(1, { message: '每页数量不能小于1' })
  @Max(100, { message: '每页数量不能超过100' })
  pageSize: number = 10;
}